package com.atom.module.mvvm.test

import android.annotation.SuppressLint
import android.graphics.Color
import android.widget.TextView

/**
 * 打开注解,就能实现 在DataBindingComponent动态的接口中 添加自定义的adapter用于设置指定的adapter
 */
abstract class HookAdapter {
    //@BindingAdapter("android:text")
    abstract fun setText(view: TextView?, value: String?)

    //@BindingAdapter("android:textColor")
    abstract fun setTextColor(view: TextView?, value: Int)
}

class ProductionBindingAdapter : HookAdapter() {
    @SuppressLint("RestrictedApi")
    override fun setText(view: TextView?, value: String?) {
        view?.text = value
    }

    override fun setTextColor(view: TextView?, value: Int) {
        view?.setTextColor(value)
    }
}

class TestBindingAdapter : HookAdapter() {
    override fun setText(view: TextView?, value: String?) {
        view?.setText("$value test");
    }

    override fun setTextColor(view: TextView?, value: Int) {
        view?.setTextColor(Color.RED)
    }
}